﻿using SqlSugar;
using System.Reflection;

namespace WarehouseManagement.Infrstructre
{
    public class SqlSugarDbContext
    {
        protected readonly ISqlSugarClient db;

        public SqlSugarDbContext(ISqlSugarClient db)
        {
            this.db = db;
        }

        public void CreatDataBase()
        {
            db.DbMaintenance.CreateDatabase();
            var rootPath = AppDomain.CurrentDomain.BaseDirectory;
            Type[] types = Assembly
                .LoadFrom(rootPath + "WarehouseManagement.Domain.dll")//如果dll报错可以换成exe
                .GetTypes().Where(it => it.FullName.Contains("WarehouseManagement.Domain.Entity"))
                .ToArray(); //断点调试，是否是需要的type
            db.CodeFirst.SetStringDefaultLength(200).InitTables(types);//创建表
        }


    }
}
